/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
*/
/*
 * WebServiceClient.java
 *
 * Created on May 14, 2002, 10:59 AM
 */

package com.webdeninteractive.xbotts.client.serviceproviders;

import com.webdeninteractive.xbotts.client.api.client.*;
import java.io.PrintStream;
import java.net.URL;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.w3c.dom.Node;
import com.webdeninteractive.toolkit.*;
import java.util.*;
/**
 * ClientService implementation for the BIE Web Service action
 * @author  jdepons
 * @version $Id: BIEWSClient.java,v 1.1.1.1 2006/01/25 13:51:12 richie93 Exp $ 
 */
public class BIEWSClient extends AbstractClientService {
    
    public ClientResponse runService(ClientRequest clientRequest) throws Exception {
        Map request = clientRequest.getProperties();

        String endPointURL = (String) request.get("endPointURL");
        
        String username=(String) request.get("username");
        String password=(String) request.get("password");
                
        
        //common data form
        String description=(String) request.get("description");
        String destinationRouteID=(String) request.get("destinationRouteID");
                
        String method = "runService";
        String i1 = destinationRouteID;
        String i2 = new String(clientRequest.getMessage());
        
        Service service = new Service();
        Call call = (Call)service.createCall();
        
        call.setUsername(username);
        call.setPassword(password);
        call.setTargetEndpointAddress(new URL(endPointURL));
        call.setOperationName(method);
        call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("op2", XMLType.XSD_STRING, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_STRING);
        String ret = (String)call.invoke(new Object[] {i1, i2});
        
        byte[] retBytes = ret.getBytes();
        
                
        ClientResponse cr = new ClientResponse(retBytes);
        
        return cr;
    }
}
